package JIndicators;

import com.dukascopy.api.indicators.*;

/**
 * @author Dmitry Shohov
 */
public class temp2 implements IIndicator {
    private IndicatorInfo indicatorInfo;
    private OptInputParameterInfo shiftOptInputParameter;
    private IIndicator smaIndicator;
    
    public void onStart(IIndicatorContext context) {
        IIndicatorsProvider provider = context.getIndicatorsProvider();
        smaIndicator = provider.getIndicator("SMA");
        indicatorInfo = new IndicatorInfo("SMA_SHIFT", "SMA with shift", "Overlap Studies", true, false, false, 1, 2, 1);
        shiftOptInputParameter = new OptInputParameterInfo("Shift", OptInputParameterInfo.Type.OTHER, new IntegerRangeDescription(0, -100, 100, 1));
    }

    public IndicatorResult calculate(int startIndex, int endIndex) {
        return smaIndicator.calculate(startIndex, endIndex);
    }

    public IndicatorInfo getIndicatorInfo() {
        return indicatorInfo;
    }

    public InputParameterInfo getInputParameterInfo(int index) {
        return smaIndicator.getInputParameterInfo(index);
    }

    public int getLookback() {
        return smaIndicator.getLookback();
    }

    public int getLookforward() {
        return smaIndicator.getLookforward();
    }

    public OptInputParameterInfo getOptInputParameterInfo(int index) {
        if (index == 0) {
            return smaIndicator.getOptInputParameterInfo(index);
        } else if (index == 1) {
            return shiftOptInputParameter;
        } else {
            return null;
        }
    }

    public OutputParameterInfo getOutputParameterInfo(int index) {
        return smaIndicator.getOutputParameterInfo(index);
    }

    public void setInputParameter(int index, Object array) {
        smaIndicator.setInputParameter(0, array);
    }

    public void setOptInputParameter(int index, Object value) {
        if (index == 1) {
            smaIndicator.getOutputParameterInfo(0).setShift((Integer) value);
        } else {
            smaIndicator.setOptInputParameter(index, value);
        }
    }

    public void setOutputParameter(int index, Object array) {
        smaIndicator.setOutputParameter(index, array);
    }
}